/**
 * Clase padre de la que heredan .
 */

package BaseDatos;

import java.util.ArrayList;
import JSON.JSONObject;



public abstract class TablaAccess {
	protected Connection miConexion;
	
	public TablaAccess(){
		miConexion = new Connection();
	}
	/*public ArrayList<JSONObject> insertRow(String tabla, String[] values){
		String t = "INSERT";
		String aux = "INSERT INTO " +tabla+ " VALUES (";
		for (int i = 0;i < values.length; i++){
			aux += "'" + values[i] + "',";
		}
		String c = aux.substring(0, aux.length()-1);
		c += ")";
		
		ArrayList<JSONObject> ar = miConexion.setData(t, c);
		
		return ar;
	}*/
	
	public ArrayList<JSONObject> insertaValores(String tabla,String atributos, String[] values){
		String t = "INSERT";
		String aux = "INSERT INTO " +tabla+" "+atributos+ " VALUES (";
		for (int i = 0;i < values.length; i++){
			aux += "'" + values[i] + "',";
		}
		String c = aux.substring(0, aux.length()-1);
		c += ")";
		
		ArrayList<JSONObject> ar = miConexion.setData(t, c);
		
		return ar;
	}
	


	public ArrayList<JSONObject> consultaSimple(String seleccion, String tabla, String condicion){
		String t = "SELECT";
		String c= "";
		if(condicion == null) c = "SELECT "+seleccion+" FROM "+tabla; 		
		else c = "SELECT "+seleccion+" FROM "+tabla+ " WHERE "+condicion;
		ArrayList<JSONObject> ar = miConexion.setData(t, c);
		return ar;
		
	}
	
	
	public ArrayList<JSONObject> actualizacionSimple(String tabla, String set, String condicion){
		String t = "UPDATE";
		String u = "UPDATE "+tabla+" SET "+set+" WHERE "+condicion;
		ArrayList<JSONObject> ar = miConexion.setData(t, u);
		return ar;
	}
	
	public ArrayList<JSONObject> borrarSimple(String tabla, String condicion){
		String t = "DELETE";
		String c= "";
		if(condicion == null) c = "DELETE * FROM "+tabla; 		
		else c = "DELETE FROM "+tabla+ " WHERE "+condicion;
		ArrayList<JSONObject> ar = miConexion.setData(t, c);
		return ar;
		
	}
	
	
	
}
